package com.team.arms.public_data.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.team.arms.public_data.domain.ListSurveyItems;
import com.team.arms.public_data.domain.SurveyOptionInformation;
import com.team.arms.public_data.domain.VisitSurveyConfiguration;
import com.team.arms.public_data.mapper.ListSurveyItemsMapper;
import com.team.arms.public_data.mapper.SurveyOptionInformationMapper;
import com.team.arms.public_data.service.VisitSurveyConfigurationService;
import com.team.arms.public_data.mapper.VisitSurveyConfigurationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class VisitSurveyConfigurationServiceImpl extends ServiceImpl<VisitSurveyConfigurationMapper, VisitSurveyConfiguration>
    implements VisitSurveyConfigurationService{

    @Autowired
    private VisitSurveyConfigurationMapper visitSurveyConfigurationMapper;
    @Autowired
    private ListSurveyItemsMapper listSurveyItemsMapper;
    @Autowired
    private SurveyOptionInformationMapper surveyOptionInformationMapper;
    @Override
    public VisitSurveyConfiguration selectAllByVisitsSurveysId(String visitsSurveysId) {
        return visitSurveyConfigurationMapper.selectAllByVisitsSurveysId(visitsSurveysId);
    }

    @Override
    public int insertAll(VisitSurveyConfiguration visitSurveyConfiguration) {
        return visitSurveyConfigurationMapper.insertAll(visitSurveyConfiguration);
    }

    @Override
    public boolean configuration(ListSurveyItems[] listSurveyItems,
                             SurveyOptionInformation[] surveyOptionInformations) {

        int num=0;
        for( ListSurveyItems listSurveyItem : listSurveyItems){
            int i = listSurveyItemsMapper.insertAll(listSurveyItem);
            if(i>0){
                for (SurveyOptionInformation surveyOptionInformation : surveyOptionInformations){
                    int j = surveyOptionInformationMapper.insertAll(surveyOptionInformation);
                }
            }
            num++;
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public List<VisitSurveyConfiguration> selectByFiled(String field, String content) {
        return visitSurveyConfigurationMapper.selectByFiled(field, content);
    }
}




